package xyz.lisys.utils;

import lombok.Data;

import java.io.IOException;
import java.util.Properties;

public class ResourceHolder {

    public static JdbcConfigObject getJdbcProp() {
        JdbcConfigObject jdbcConfigObject = new JdbcConfigObject();

        try {
            Properties props = new Properties();
            props.load(Thread.currentThread().getContextClassLoader().getResourceAsStream("jdbc.properties"));

            jdbcConfigObject.setDriver(props.getProperty("jdbc.driver"));
            jdbcConfigObject.setUrl(props.getProperty("jdbc.url"));
            jdbcConfigObject.setUsername(props.getProperty("jdbc.username"));
            jdbcConfigObject.setPassword(props.getProperty("jdbc.password"));
        } catch (IOException ignored) {
        }

        return jdbcConfigObject;
    }

    public static RedisConfigObject getRedisProp() {
        RedisConfigObject redisConfigObject = new RedisConfigObject();

        try {
            Properties props = new Properties();
            props.load(Thread.currentThread().getContextClassLoader().getResourceAsStream("jedis.properties"));

            redisConfigObject.setHost(props.getProperty("jedis.host"));
            redisConfigObject.setPassword(props.getProperty("jedis.password"));
        } catch (IOException ignored) {
        }

        return redisConfigObject;
    }

    @Data
    public static class JdbcConfigObject {
        private String driver;
        private String url;
        private String username;
        private String password;
    }

    @Data
    public static class RedisConfigObject {
        private String host;
        private String password;
    }
}
